package com.suzj.extraenchantments.item;

import java.util.List;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;


public class ItemWuTongGuo extends Item {
    private static final FoodProperties food = new FoodProperties.Builder().saturationMod(2.0f).nutrition(2).effect(() -> {
        return new MobEffectInstance(MobEffects.ABSORPTION, 60, 1);
    }, 1.0f).build();

    public ItemWuTongGuo() {
        super(new Item.Properties().food(food) );
    }

    @Override
    public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity entityLiving) {
        if (entityLiving instanceof Player player) {

            CompoundTag CompoundTag = new CompoundTag();
            player.addAdditionalSaveData(CompoundTag);
            CompoundTag.putInt("XpSeed", 0);
            player.readAdditionalSaveData(CompoundTag);
            player.displayClientMessage(Component.translatable("extraenchantments.message.wutongguo"), true);
        }
        return isEdible() ? entityLiving.eat(level, stack) : stack;
    }



    @Override
    public void appendHoverText(ItemStack pStack, @org.jetbrains.annotations.Nullable Level pLevel, List<Component> pTooltipComponents, TooltipFlag pIsAdvanced) {
       pTooltipComponents.add(Component.translatable("extraenchantments.desc.wutongguo1"));
       pTooltipComponents.add(Component.translatable("extraenchantments.desc.wutongguo2"));
        super.appendHoverText(pStack, pLevel, pTooltipComponents, pIsAdvanced);
    }



    public boolean isFoil(ItemStack stack) {
        return true;
    }
}